package Accessors;

import Callbacks.AbstractCallback;
import Models.Movement;
import Presenter.MovementPresenter;
import android.app.ProgressDialog;
import android.content.Context;

@SuppressWarnings("rawtypes")
public class MovementAccessor extends AbstractAccessor<Movement,MovementPresenter,AbstractCallback> {
	private final String NAME = "movement";
	private final String DIALOG = "Movement";
	
	private final static MovementPresenter presenter = new MovementPresenter();
	
	//Modal dialog variable.
	ProgressDialog modalDialog = null;
	
	public MovementAccessor(AbstractCallback callback){
		super(presenter, callback);
	}
	
	//Public access functions.
	public void getAllItems(final Context context){
		String dialog = "Loading " + DIALOG + " List...";
		String rfString = NAME;
		super.getAllItems(context, dialog, rfString);
	}
	
	public void getItem(final int id, final Context context){
		String dialog = "Loading " + DIALOG + "...";
		String rfString = NAME + "/" + Integer.toString(id);
		super.getItem(context, dialog, rfString);
	}
	
	public void doItemUpdate(final Movement item, final Context context){
		String dialog = "Updating " + DIALOG + "...";
		String rfString = NAME;
		super.doItemUpdate(item, context, dialog, rfString);
	}
	
	public void doItemInsert(final Movement item, final Context context){
		String dialog = "Inserting " + DIALOG + "...";
		String rfString = NAME;
		super.doItemInsert(item, context, dialog, rfString);
	}
	
	public void doMovementInsertWithBrewUpdate(final Context context, final Movement movement
			, final double temp, final double grav, final java.sql.Time time, final String notes
			, final double vol, final double psi, final int brewVersion){
		String dialog = "Inserting " + DIALOG + "...";
        final String tempStr = Double.toString(temp);
        final String gravStr = Double.toString(grav);
        final String timeStr = time.toString();
        final String volStr = Double.toString(vol);
        final String psiStr = Double.toString(psi);
		String rfString = NAME + "/createAndUpdateVCheck/"+ tempStr + "/" + gravStr + "/" + timeStr + "/" 
                + notes + "/" + volStr + "/" + psiStr + "/" + brewVersion;
		rfString = rfString.replaceAll(" ", "%20");
		super.doItemInsert(movement, context, dialog, rfString);
	}
}
